home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Game / M / MacPool.cpt / MacPool / Billiard Parlour.Help next >
Encoding:
Text File  |  1985-12-23  |  13.5 KB  |  274 lines  |  [TEXT/RCMP]

  1.  
  2. General Operation
  3.  
  4. Each game has a CUE BALL, except Billiards has two.  A cue ball may be
  5. launched with the mouse.  This is done by placing the mouse near the ball,
  6. pressing, then dragging out a cue line.  The ball is launched upon release
  7. of the mouse button, with speed proportional to the dragged length of the
  8. cue line and direction determined by the line.  No ball other than cue 
  9. ball(s) may be shot; for Billiards the launched ball is always the one 
  10. closest to the initial press-down point of the mouse.
  11.  
  12. Be careful not to shoot too hard - if you 'slam' a nearby object ball, you
  13. may get a 'hop' and not hit the object solidly.  A little practice will
  14. reveal this.  
  15.  
  16. You can arrange balls by holding down the Option key of the keyboard while
  17. you press on, and subsequently drag, a ball.  A menu item 'Arrange Balls'
  18. also performs this function, but must be deselected after arrangement is
  19. complete.  
  20. >>
  21. A hand-cursor results whenever balls may be arranged.  Sunk 
  22. balls deposited near the bottom of the screen can be moved back onto the 
  23. table without recourse to the Option key or menu.
  24.  
  25. ENGLISH is invoked by selecting same on the Options menu, upon which a 
  26. picture of the cue ball face appears to the right of the table. The white 
  27. spot shows where the next shot will strike the cue ball.  Note two things: 
  28. the spot reverts to the default position after each shot, and this default 
  29. lies at the theoretical zero-english height of 7/5 radius.
  30.  
  31. The collision sounds may be turned on or off via the Options menu item
  32. 'Sound'.  Likewise, 'English' has the effect of hiding or bringing
  33. back the English display.  This menu item does not affect the value of
  34. English, which in any case always reverts to zero after any shot.
  35. >>
  36. SCORING may be performed with the 100-carrom scoring rack atop the screen.  
  37. To use the carroms simply drag them to and fro.  The TURN SCORE is 
  38. always reported in the central display just below the carrom rack.  This 
  39. is the number of balls sunk on the previous turn.  For straightforward 
  40. turns the number will be the amount to add into the current player's 
  41. cumulative score.  For scratches, etc. one has to carefully apply whatever 
  42. scoring rules have been agreed upon; in such cases the central display is 
  43. intended as a guide, not an actual score.
  44.  
  45. SCRATCHES are reported (as beeps) when the cue ball is sunk, or in
  46. 8-ball when the 8 is sunk.  For cue ball scratches, the ball is placed
  47. in the right-hand half of the table, at an open location.  As usual the
  48. cue ball may be moved with the Option key or the Options menu entry
  49. 'Arrange Balls'.
  50. >>
  51. REPLAY, UNDO, SAVE SHOT and LOAD SHOT recall play from the past.  UNDO just
  52. sets up the previous shot.  REPLAY does an undo plus shoots again for you
  53. with the identical cue parameters.  SAVE SHOT saves to disk the previous
  54. shot and cue parameters.  LOAD SHOT recovers from a disk a previously saved
  55. shot.  To see the action from disk, choose LOAD SHOT and an appropriate
  56. file.  Then do REPLAY (or use the cue again on the loaded position).  Note
  57. that LOAD SHOT also loads in the game that was in effect when you saved.
  58. >>
  59.  
  60. The Games
  61.  
  62. In BILLIARDS the players alternate between the spotted and unspotted cue
  63. balls.  A score is logged on the central display when the current cue ball
  64. strikes the other two object balls, but only if three rails are hit
  65. by the cue ball before the second object ball is struck.
  66.  
  67. In POOL the rack is numbered consecutively from 1 through 15, and
  68. sunk balls will be deposited in numerical order.
  69.  
  70. In 8-BALL the rack has a central 8 ball, with a certain pattern of solids
  71. and stripes surrounding, and sunk balls are deposited with solids to the
  72. left and stripes to the right.  There are many different 'favorite' 8-Ball 
  73. rack configurations:  the one chosen for this program guarantees a fairly 
  74. even distribution of stripe/solid placement over a number of breaks. 
  75. >>
  76. In 9-BALL the rack has a central 9 ball, with a certain pattern of balls 1
  77. through 8 surrounding.  Sunk balls are deposited in numerical order.
  78.  
  79. In SNOOKER there are fifteen unmarked balls in the rack, with numbered 
  80. balls 2,3,4,5,6,7 in specific places.  Sunk balls are deposited in two 
  81. groups: numbered and unmarked.
  82.  
  83. In SLOP there are optional rack sizes, and all object balls are unmarked. 
  84.  
  85. The LAG game simply automates the 'lagging' process in which players 
  86. alternately launch a cue ball to see who can come closer to a point or 
  87. rail.  As with other options, players may choose their own lag criteria, 
  88. with the program providing decision aid - in this case a lag line is drawn 
  89. on the screen to indicate final cue ball position.  The lag also has the 
  90. feature that the cue ball may be either dragged or shot while the item is 
  91. checked.  NOTE: This item must be deselected to enable any other game.
  92. >>
  93.  
  94. The Racks
  95.  
  96. The menu items 'Rack' and 'Next Rack' provide means for
  97. setting up games.  'Rack' is used to start afresh.  'Next Rack' makes the 
  98. most sense in Straight Pool variations, by racking all but
  99. the final ball left on the table.  If the number of object balls left is 
  100. less than or greater than one, or if the single ball left is within the 
  101. 15-ball racking triangle the full Rack results as a default.
  102. >>
  103. Magnification
  104.  
  105. This is to aid in reading ball numbers and assessing complex positions.
  106.  
  107.   Glass:  A rectangle will follow the mouse movements.  Hold down the
  108.           mouse button to magnify the selected area.  An <Option>-Click
  109.           or a Double-click will cause the magnifying glass to disappear.
  110.   Screen:  The table is blown up to greater than full-screen size.  
  111.           Drag the mouse, with the button held down, to scroll the 
  112.           full screen display (as in MacPaint 'ShowPage' mode). An 
  113.           <Option>-Click or a Double-click will cause the screen
  114.           to revert to normal.
  115.  
  116.  
  117. Note:  The startup display (with animated Billiard Parlour scene) may be
  118.        speeded up by holding down the <Option> key.  Also, holding down
  119.        this key steadily while you boot the application will set the sound
  120.        off (this is useful for Hyperdrives and other Macintosh mods which
  121.        do not properly handle the sound drivers).
  122. ~~
  123.  
  124. Origins of Billiard Parlour
  125.  
  126. The project was conceived as a sharp test of Rascal animation.  We had
  127. worked out fast 'integer calculus' routines for colliding bodies and
  128. performing various rapid graphics functions. These formulas and techniques
  129. coupled with bit-copying of ball images formed the basis for
  130. the reasonably realistic billiard effects.  The final application was thus
  131. written entirely within the Rascal compiler/development system 
  132. environment.
  133.  
  134. The following technical remarks may be of interest to the serious 
  135. programmer.
  136. >>
  137. Perhaps the most salient fact about the billiards algorithms is that no
  138. floating point is used whatsoever.  All calculations are done in 16-bit
  139. integer format.  The reason, of course, is the quest for speed.  Though
  140. floating point variables are easier to work with for dynamical problems,
  141. there is no hope for full pool table dynamics on the Macintosh unless
  142. integer calculations predominate.
  143. >>
  144. The speed of the integer dynamical routines should be evident from a
  145. consideration of what must be done to iterate an entire ensemble of hard
  146. spheres.  Say there are N spheres total in motion on the table.  One must
  147. on every pass of the main iteration loop
  148.  
  149.      1) Update 2N coordinate values.
  150.      2) Update 2N velocity values.
  151.      3) Seek and analyze collisions, requiring N*N/2 checks.
  152.      4) Handle damping and English.
  153.      5) For most games, check for pocket sinking for each of the N balls.
  154.      6) Check for rail bounces for each of N balls.
  155.      
  156. Naturally, some of the above are interrelated - for example collision and
  157. damping are what imply the need for updating velocities.  The fact that
  158. N*N/2 checks are used to seek all collisions is especially cumbersome when
  159. the number N in the ensemble is large.  For a full pool table, this means
  160. 128 checks for collisions are made at each iteration.
  161. >>
  162. An example of trickery intended to optimize speed is that used to check 
  163. for collisions.  The Rascal source has a collision algorithm essentially 
  164. like so:
  165.  
  166.      s := 4*radius*radius;
  167.      loop(,i:=0,++i,i>numballs-1)
  168.      {
  169.        loop(i<numballs-1, j:=i+1, ++j, j>numballs-1)
  170.        {
  171.            dx := x[i] - x[j];
  172.            if dx*dx <= s then
  173.               { dy:= y[i] - y[j];
  174.                 if dx*dx + dy*dy <= s then
  175.                    collide(i,j);
  176.               };
  177.        };
  178.      };
  179. >>
  180.  
  181. The two loops are straightforward, dictating that we are checking for
  182. pair (i,j) collisions where i is not equal to j.  But the primary point is 
  183. that the check dx*dx<s is made first to save time.  Note that two balls 
  184. have collided (that is, penetrate each other) whenever
  185.  
  186.     sqrt(dx*dx + dy*dy) <= 2*radius
  187.     
  188. so collision also implies sqrt(dx*dx)< 2*radius.  The 'sqrt' function can
  189. be dropped, as in the explicit loop above, in the interest of speed.
  190.  
  191. Many such integer calculations were necessary to achieve a certain 
  192. realism.  
  193. >>
  194. Other examples which might interest the programmer are:
  195.  
  196.      1) Each ball has two pictures, which alternate after every multiple
  197.         of pi*radius is moved on the screen.  This gives an impression of
  198.         rolling.
  199.      2) Damping is hard to accomplish with integers.  The primary problem
  200.         is that if we attempt at each iteration something like:        
  201.               vx[i]:= (vx[i]*999)/1000;
  202.               vy[i]:= (vy[i]*999)/1000;              
  203.         then, in general, one of vx or vy will vanish completely before 
  204.         the other, at the tail end of a ball's motion.  This causes 
  205.         swerving at the end of the trajectory, as a ball disappointingly 
  206.         follows one axis or the other.  The solution was to apply the 
  207.         formula only at certain times - not in each iteration - and make 
  208.         sure that total damping is achieved before the final swerve.  This 
  209.         last effect is done by simply stopping the motion after a certain 
  210.         iteration count which depends in turn on the game played and on 
  211.         other conditions.
  212. >>
  213.      3) The difficulty with integer calculus is evident when one considers
  214.         the basic Newtonian iteration:
  215.         
  216.              x[i]:= x[i] + vx[i];
  217.              y[i]:= y[i] + vy[i];
  218.              
  219.         noting that in real-number calculus one would have each velocity
  220.         term multiplied by a small time increment dt.  Because we cannot
  221.         do this with integers (the smallest increment being 1) there is
  222.         the threat that balls will move very far at each iteration.  The
  223.         solution is easy enough: hold all coordinates and velocities as 
  224.         large integers, and divide by a constant only when actually 
  225.         graphing.  Thus in Billiard Parlour the typical coordinates are on 
  226.         the order of 10000 and divisions by 100 are typical at graph time.
  227. >>
  228.      4) The problem of English is a good example of a tough-sounding 
  229.      problem which turns out to be rather trivial to solve.  For English 
  230.      effects at a rail, we add to the reflected velocity the following 
  231.      cross- product expression:
  232.         
  233.               k(omega X velocity)
  234.               
  235.      where omega is a unit vector normal to the plane of the table and 
  236.      indicating angular rotation, while k is the value of (horizontal)
  237.      English.  For vertical English at a rail, we simply add to the normal 
  238.      reflected component Vn the quantity h*Vn where h is now the vertical 
  239.      English.  These rules are not completely exact physically, but it is 
  240.      easy to show that the major qualitative behavior of English at rails 
  241.      is handled correctly with these simple calculations.  For English 
  242.      during ball-ball encounters, the same formula are used, but relegated 
  243.      of course to the center-of-momentum frame, where each ball sees in 
  244.      effect the other ball as a 'rail'.
  245. >>
  246.      5) Billiard Parlour dynamical calculations are not exact, and for the
  247.         sake of speed some 'molecular' effects - in which balls stick 
  248.         together momentarily - have been left in.  These effects occur 
  249.         primarily because of the ambiguity between incoming and outgoing 
  250.         collisions: if two balls mutually penetrate, it is not easy to 
  251.         find out whether they have just had their velocities reflected, or 
  252.         whether now is the time to so reflect.  The ambiguity is 
  253.         especially fierce when many balls are banging around in a clutch.  
  254.         So the application was designed for speed: there is a molecule 
  255.         from time to time, but the molecule does not normally stay together.  
  256.         Removing all unrealistic effects proves to take too much compute 
  257.         time away from the otherwise pleasing motion.
  258. >>
  259. The serious programmer may also be interested in the various utilities and
  260. methods unrelated to dynamics that went into the project.  The 
  261. magnification feature for reading balls and positions easily is a good 
  262. example of Rascal off-screen port graphics.  The sound of ball clicks is 
  263. achieved by free-form synthesis of 'chirp' waves - i.e. high-frequency, 
  264. brief tone bursts.  The graphics problem presented by the carroms scoring 
  265. rack is surprisingly difficult, and stands as a good example of straight 
  266. quickdraw methods.
  267.  
  268. The key graphics procedures are found on the standard Rascal Jan 1986
  269. release as library entries.  The key library is called __GraphUtils, and
  270. has many routines from screen initialization to high-speed sine, cosine, and
  271. square root functions; in general integer techniques for fast graphics.
  272. But other libraries are involved heavily - the interested programmer can
  273. consult the Billiard Parlour source listing in conjunction with the Rascal
  274. User Manual.